package com.libre.business.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.libre.business.entity.Form;
import com.libre.business.service.FormService;
import com.libre.common.base.BaseController;
import com.libre.common.enums.ResultEnum;
import com.libre.common.utils.PageUtil;
import com.libre.common.utils.ResultUtil;
import com.libre.common.vo.PageVo;
import com.libre.common.vo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RequestMapping("/form")
@RestController
public class FormController extends BaseController {

    @Autowired
    private FormService formService;

    @GetMapping("/findPage")
    public Result<IPage<Form>> findPage(@ModelAttribute PageVo pageVo, @ModelAttribute Form form) {
        IPage<Form> page = formService.findPage(PageUtil.initMpPage(pageVo), form);
        return new ResultUtil<IPage<Form>>().setData(page);
    }

    @PostMapping("/save")
    public Result save(@RequestBody Form form) {
        formService.save(form);
        return new ResultUtil().setSuccessMsg(ResultEnum.OK.getReasonPhraseCN());
    }

    @PostMapping("/update")
    public Result update(@RequestBody Form form) {
        formService.updateById(form);
        return new ResultUtil().setSuccessMsg(ResultEnum.OK.getReasonPhraseCN());
    }

}
